package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.ContractRoomPriceModel;
import com.jiayang.hhotel.bean.ContractTimeModel;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Administrator on 2017/5/26 0016.
 * 合同时间和合同房价列表适配器
 */

public class ContractTimeListAdapter extends SwipeMenuAdapter<ContractTimeListAdapter.ViewHolder> {

//    private static final int TYPE_ITEM =0; //普通Item View
//    private static final int TYPE_FOOTER = 1; // 底部FootView
    public static final int FLAG_CONTRACT_TIME=2;//合同时间标记
    public static final int FLAG_CONTRACT_ROOM_PRICE=3;//合同房价标记


    private List<ContractTimeModel.PTaContractDateListDtoBean> mTimeList;
    private List<ContractRoomPriceModel.PTaContractRmRateListDtoBean> priceList;

    private Context t;
    private int flag;

    public ContractTimeListAdapter(Context context, List<ContractTimeModel.PTaContractDateListDtoBean> list,List<ContractRoomPriceModel.PTaContractRmRateListDtoBean> ml, int flag){
        this.mTimeList=list;
        this.priceList=ml;
        this.t=context;
        this.flag=flag;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        switch (flag){
            case FLAG_CONTRACT_ROOM_PRICE://合同房价
                ContractRoomPriceModel.PTaContractRmRateListDtoBean model= priceList.get(position);
                holder.titleOne.setText(t.getString(R.string.tuanhuifangjia));
                holder.titleTwo.setText(t.getString(R.string.sankefangjia));
                holder.titleThree.setText(t.getString(R.string.jibie));

                holder.startDate.setText(model.getGrpRmRate()+t.getString(R.string.yuan));
                holder.endDate.setText(model.getGstRmRate()+t.getString(R.string.yuan));
                holder.level.setText(model.getRmType());
                break;
            case FLAG_CONTRACT_TIME://合同时间
                ContractTimeModel.PTaContractDateListDtoBean time= mTimeList.get(position);
                holder.titleOne.setText(t.getString(R.string.start_date));
                holder.titleTwo.setText(t.getString(R.string.end_date));
                holder.titleThree.setText(t.getString(R.string.grade));

                holder.startDate.setText(time.getBeginDate());
                holder.endDate.setText(time.getEndDate());
                holder.level.setText(time.getGrade()+"");
                break;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        switch (flag){
            case FLAG_CONTRACT_ROOM_PRICE:
                return priceList.size();
            case FLAG_CONTRACT_TIME:
                return mTimeList.size();
        }
        return 0;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.contract_time_list_item, parent, false);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    class ViewHolder extends RecyclerView.ViewHolder implements Serializable{

        TextView titleOne;//第一行标题名
        TextView titleTwo;//第二行标题名
        TextView titleThree;//第三行标题名

        TextView startDate;//开始日期/团会房价
        TextView endDate;//结束日期/散客房价
        TextView level;//等级/级别

        public ViewHolder(View convertView) {
            super(convertView);


            startDate= (TextView) convertView.findViewById(R.id.tv_start_time);
            endDate= (TextView) convertView.findViewById(R.id.tv_end_time);
            level= (TextView) convertView.findViewById(R.id.tv_level);
            titleOne= (TextView) convertView.findViewById(R.id.tv_one);
            titleTwo= (TextView) convertView.findViewById(R.id.tv_two);
            titleThree= (TextView) convertView.findViewById(R.id.tv_three);
        }
    }
}
